package com.yjt.admin.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yjt.admin.system.entity.GroupType;
import com.yjt.admin.system.form.EmplyForm;
import com.yjt.admin.system.form.GroupTypeForm;
import com.yjt.admin.system.param.EmplyParam;
import com.yjt.admin.system.param.GroupTypeParam;
import com.yjt.admin.system.service.GroupTypeService;
import com.yjt.admin.system.vo.EmplyVO;
import com.yjt.admin.system.vo.GroupTypeVO;
import com.yjt.common.enums.ModulEnum;
import com.yjt.common.enums.OperTypeEnum;
import com.yjt.common.log.annotation.OperLog;
import com.yjt.common.vo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 群组类别表 前端控制器
 * </p>
 *
 * @author zzp
 * @since 2021-10-13
 */
@RefreshScope // 支持Nacos的动态刷新功能
@RestController
@RequestMapping("/admin/system/group-type")
@Api(tags = "群组类别管理")
public class GroupTypeController {

    @Autowired
    private GroupTypeService groupTypeService;

    @PostMapping("/add")
    @ApiOperation(value = "增加群组类别信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.GROUP_TYPE_MODUL, operType = OperTypeEnum.ADD, operDesc = "新增群组类别信息")
    public CommonResult addGroupType(@RequestBody GroupTypeForm groupTypeForm) {
        GroupType groupType = new GroupType();
        BeanUtils.copyProperties(groupTypeForm,groupType);
        groupTypeService.save(groupType);
        return CommonResult.success("群组类别新增成功");
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "删除群组类别信息", notes = "返回JSONObject", hidden = true)
    @ApiImplicitParam(name = "groupTypeId", value = "群组类别id")
    @OperLog(operModul = ModulEnum.GROUP_TYPE_MODUL, operType = OperTypeEnum.DEL, operDesc = "删除群组类别信息")
    public CommonResult delGroupType(String groupTypeId) {
        groupTypeService.removeById(groupTypeId);
        return CommonResult.success("群组类别删除成功");
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改群组类别信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.GROUP_TYPE_MODUL, operType = OperTypeEnum.MOD, operDesc = "修改群组类别信息")
    public CommonResult updateGroupType(@RequestBody  GroupTypeForm groupTypeForm) {
        GroupType groupType = new GroupType();
        BeanUtils.copyProperties(groupTypeForm,groupType);
        groupTypeService.updateById(groupType);
        return CommonResult.success("群组类别修改成功");
    }

    @GetMapping("/{groupTypeId}")
    @ApiOperation(value = "查询人员信息", notes = "返回JSONObject")
    @ApiImplicitParam(name = "groupTypeId", value = "群组类别id")
    public CommonResult<GroupTypeVO> getOneGroupType(@PathVariable String groupTypeId) {
        return CommonResult.success(groupTypeService.getOneGroupType(groupTypeId), "群组类别信息查询成功");
    }


    @PostMapping("/list-page")
    @ApiOperation(value = "查询分页人员信息", notes = "返回JSONObject")
    public CommonResult<IPage<GroupTypeVO>> getPageGroupType(@RequestBody GroupTypeParam groupTypeParam) {
        return CommonResult.success(groupTypeService.getPageGroupType(groupTypeParam), "查询群组类别分页信息成功");
    }


}
